<?php

/**
 * Ares Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 * @author xingkun
 * @date 2014/11/07
 */
class ApiCController extends CController {

    /**
     * process parameter to integer for security
     * 
     * @param  string           $str
     * @return integer|null     
     */
    public function getInt($str) {
        if (!isset($str)) {
            return null;
        } else {
            return intval($str);
        }
    }

    /**
     * process parameter to string for security
     * 
     * @param  string $str 
     * @return string
     */
    public function getString($str) {
        $str = trim($str);
        return addslashes($str);
    }

    /**
     * get request parameter
     * 
     * @param  string $name fieldname
     * @return array
     */
    public function getParam($name) {
        return Yii::app()->request->getParam($name);
    }

    /**
     * 将Yii模型对象转为数组(多维)
     * 
     * @param  object $models          [description]
     * @param  array $filterAttributes [description]
     * @return array                   [description]
     *
     * @todo 格式化
     */
    public function convertModelToArray($models, array $filterAttributes = null) {
        if ($models == null) {
            return array();
        } else {
            return OBJTool::convertModelToArray($models, $filterAttributes);
        }
    }

}
